package com.xlh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xlh.common.Result;
import com.xlh.param.DelByIdParam;
import com.xlh.param.UserCreateOrUpParam;
import com.xlh.param.UserListParam;
import com.xlh.service.UserService;
import com.xlh.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户 controller
 * <p>
 * Created by cfz
 */
@Api(tags = "UserController", description = "用户controller")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("用户列表")
    @GetMapping("/list")
    public Result<IPage<UserVO>> list(UserListParam userListParam) {

        IPage<UserVO> page = userService.list(userListParam);
        return Result.success(page);
    }


    @ApiOperation("创建用户")
    @PostMapping("/create")
    public Result create(UserCreateOrUpParam userListParam) {

        userService.create(userListParam);
        return Result.success();
    }


    @ApiOperation("删除用户")
    @PostMapping("/delete")
    public Result del(DelByIdParam delByIdParam) {

        userService.removeBatchByIds(delByIdParam.getIds());
        return Result.success();
    }


    @ApiOperation("修改用户")
    @GetMapping("/update")
    public Result update(UserCreateOrUpParam upParam) {

        userService.update(upParam);
        return Result.success();
    }

}
